package cn.tudu.coolshark.controller;

import cn.tudu.coolshark.mapper.CategoryMapper;
import cn.tudu.coolshark.pojo.entity.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CategroyController {

    @Autowired(required = false)
    CategoryMapper categoryMapper;
    @RequestMapping("/categroy/select")
    public List<Category> select(){
        return categoryMapper.select();
    }
    @RequestMapping("category/delete")
    public void delete(int id){
        categoryMapper.deleteById(id);
    }
    @RequestMapping("/category/insert")
    public List<Category> insert(String name){
        categoryMapper.insert(name);
        return categoryMapper.select();
    }
    @RequestMapping("/category/update")
    public void update(@RequestBody Category category){
        categoryMapper.update(category);
    }
}
